package com.imeth.cms.service.impl;

import com.imeth.base.model.Paging;
import com.imeth.cms.Category;
import com.imeth.cms.dao.CategoryDao;
import com.imeth.cms.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by peter on 12/24/2015.
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    CategoryDao categoryDao;

    public int save(Category category) {
        return categoryDao.save(category);
    }

    public int update(Category category) {
        return categoryDao.update(category);
    }

    public Category getById(Integer id) {
        return categoryDao.getById(id);
    }

    public List<Category> query(Paging paging) {
        Integer records = categoryDao.count();
        paging.setRecords(records);
        return categoryDao.query(paging);
    }

    public int batchDelete(List<Integer> ids) {
        for (Integer id : ids) {
            categoryDao.deleteById(id);
        }
        return ids.size();
    }
}
